package Test02;

import java.util.Scanner;

/*5、判断年、月、日是否合法
从键盘输入年、月、日，要求年份必须是正整数，月份范围是[1,12]，日期也必须在本月总天数范围内，
如果输入正确，输出“年-月-日”结果，否则提示输入错误。
注意：需要考虑闰年的情况

 */
public class Demo05 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入正整数的年份：");
        int year = input.nextInt();
        System.out.println("请输入月份【1-12】：");
        int month = input.nextInt();
        System.out.println("请输入日期：");
        int day = input.nextInt();
        if (year % 4 == 0 && year % 100 != 0 && year % 400 == 0) {
            if (month >= 1 && month <= 12) {
                if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 && day <= 31) {
                    System.out.println("输出日期为：" + year + "年" + month + "月" + day + "日");
                } else if (month == 4 || month == 6 || month == 9 || month == 11 && day <= 30) {
                    System.out.println("输出日期为：" + year + "年" + month + "月" + day + "日");
                } else if (month == 2 && day <= 29) {
                    System.out.println("输出日期为：" + year + "年" + month + "月" + day + "日");
                } else {
                    System.out.println("输入错误");
                }
            } else {
                System.out.println("输入错误");
            }
        }
        if (month >= 1 && month <= 12) {
            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 && day <= 31) {
                System.out.println("输出日期为：" + year + "年" + month + "月" + day + "日");
            } else if (month == 4 || month == 6 || month == 9 || month == 11 && day <= 30) {
                System.out.println("输出日期为：" + year + "年" + month + "月" + day + "日");
            } else if (month == 2 && day <= 28) {
                System.out.println("输出日期为：" + year + "年" + month + "月" + day + "日");
            } else {
                System.out.println("输入错误");
            }
        } else {
            System.out.println("输入错误");
        }
    }
}
